<style scoped>
.layui-row {
    overflow: hidden;
}

.select-item {
    width: 34.333333%;
    float: right;
}

.layui-row:after,
.layui-row:before {
    clear: none;
}

.layui-form>>>.layui-form-select {
    z-index: inherit;
}
</style>

<template>
<div class="organization">
    <div>
        <a href="javascript:;" class="layui-btn" @click="add"><i class="layui-icon">&#xe654;</i>添加质检项配置</a>
    </div>
    <form class="layui-form ">
        <div class="layui-col-lg4 select-item" style="text-align: right;width: auto">
            <div class="layui-inline" style="width: 300px">
                <select v-model="qaMainGuid" name="qaMainGuid" id="qaMainGuid" placeholder="请选择质检标准" class="layui-input layui-unselect">
                    <option value="">请选择质检标准</option>
                </select>
            </div>
            <button type="button" class="layui-btn sou" @click="search">搜索</button>
        </div>

    </form>
    <table class="layui-table layui-form">

        <thead>
            <tr>
                <th>关联类型</th>
                <th>采收批次编号</th>
                <th>质检标准</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>操作</th>

            </tr>
        </thead>
        <tbody>
            <tr class="id9" v-for="(val, index) in qaitems" :key="val.guid">
                <td>{{val.relationtypeText}}</td>
                <td>{{val.batchname}}</td>
                <td>{{val.qamainname}}</td>
                <td><template v-if="val.status == 1">生效</template> <template v-if="val.status == 2">禁用</template></td>
                <td>{{val.createtime}}</td>
                <td><a href="javascript:;" @click="edit(val.guid)">修改</a> | <a href="javascript:;" @click="del(val.guid)">删除</a></td>
            </tr>
        </tbody>
    </table>

    <Pagination :cur="currentPage" :all="totalPage" :callback="turnPage"></Pagination>
    <div style="height: 200px"></div>
</div>
</template>

<script>
import Pagination from '../common/Pagination.vue'
export default {
    name: 'Qaitems',
    components: {
        Pagination
    },
    data() {
        return {
            qaitems: [],
            currentPage: 1,
            totalPage: 0,
            searchName: '',
            qaMainGuid: ""
        }
    },
    mounted() {
        let that = this;
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;
            that.getPageData();
        });
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;

            let loader = layer.load();
            $.ajax({
                url: '/trace/Qamain!get.action',
                data: {},
                type: "post",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (res.info != "error") {

                        $.each(res, function (index, item) {

                            $('#qaMainGuid').append("<option   value=" + item.guid + " >" + item.qaname + "</option>");

                        });

                        form.render('select');
                    } else {
                        that.toast("系统错误");
                    }
                },
                complete: function () {
                    layer.close(loader);
                }
            });

        });
    },
    methods: {
        search: function () {
            this.getPageData('search');
        },
        turnPage: function (data) {
            this.currentPage = data;
            this.getPageData();
        },
        getPageData: function (type = '') {
            let that = this;
            let loader = layui.layer.load();

            let postData = {};
            if (type != 'search') {
                postData.page = that.currentPage;
            } else {
                postData.page = 1;
            }
            postData.datacategoryName = $("#searchName").val();
            that.searchName = postData.datacategoryName;

            postData.qamainguid = $("#qaMainGuid").val();
            that.qamainguid = postData.qaMainGuid;

            $.ajax({
                url: '/trace/Qaassignment!listVUEPC.action',
                type: "post",
                data: postData,
                dataType: "json",
                success: function (res) {
                    console.log(res)
                    if (res.info != undefined && res.info.rows != undefined) {
                        //分页数据赋值
                        // that.currentPage = res.info.indexPage;
                        that.totalPage = res.info.pageCount;
                        that.qaitems = res.info.rows;
                    } else {
                        that.alert("系统错误");
                    }
                },
                complete: function () {
                    layer.close(loader);
                }
            });
        },
        add: function () {
            this.$parent.switchPage('QaassignmentAdd');
        },
        edit: function (id) {
            this.$parent.gid = id;
            this.$parent.switchPage('QaassignmentEdit');
        },
        del: function (id) {
            let that = this;
            layer.confirm('确定要删除该数据？', function () {
                let loader = layer.load();
                $.ajax({
                    url: '/trace/Qaassignment!del.action',
                    type: "post",
                    data: {
                        guid: id
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.info == "success") {
                            that.toast("删除成功");
                            that.getPageData();
                        } else {
                            that.toast('系统错误！');
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });

            })
        },

    }
}
</script>
